package cn.itcast.controller;

import cn.itcast.domain.Account;
import cn.itcast.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 *  账户web
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private IAccountService accountService;

    /**
     *  查询所有的数据
     * @return 跳转list.jsp页面
     */
    @RequestMapping("/findAll")
    public String findAll(Model model) {
        System.out.println("表现层:查询所有的账户");
        List<Account> accounts = accountService.findAll();
        model.addAttribute("accounts", accounts);
        return "list";
    }

    @RequestMapping("/save")
    public String save(Account account) {
        System.out.println("表现层:保存用户");
        accountService.saveAccount(account);

        return "redirect:/account/findAll";
    }
}
